//
//  HomeViewController.m
//  jingdongfang
//
//  Created by LJL on 16/6/22.
//  Copyright © 2016年 BOE. All rights reserved.
//

#import "HomeViewController.h"
#import "IGMyiGalleryVC.h"
#import "HomeBannerCell.h"
#import "HomeViewBtnCell.h"
#import "HomeReusableView.h"
#import "HomeHDCell.h"
#import "HomeDailyCell.h"
#import "HomeArtistCollectionCell.h"
#import "IGHomePageApi.h"
#import "TopicVC.h"
#import "ArtistTableVC.h"
#import "HomeActivityCell.h"
#import "IGHomeReusableModel.h"
#import "HomeArtWorkCell.h"
#import "IGHomePageLastUploadApi.h"
#import "IGHomeHDApi.h"
#import "IGHomeDailyActivityApi.h"
#import "IGHomeArtistApi.h"
#import "HomeHDVC.h"
#import "IntroViewController.h"
#import "ZTXQViewController.h"
#import "IGPictureListDetailVC.h"

#import "IGSearchVC.h"
#import "NotFindDeviceView.h"
#import "IGPushiGalleryListVC.h"
#import "IGiGalleryPushApi.h"
#import "IGiGalleryListApi.h"
#import "XiangQingViewController.h"
#import "IGNetReachable.h"
#import "IGNoNetWorkVC.h"
#import "IGEmptyView.h"
#import "IGAppVersionManager.h"
#import "IGPopPictureManager.h"
#import "IGReportTypeApi.h"
#import "IGBatchRequestGroup.h"
#import "IGExhibitionVC.h"
#import "IGCompetitionVC.h"


@interface HomeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, DZNEmptyDataSetDelegate, DZNEmptyDataSetSource>
{
    NSString *pageNumber;//页数，从0开始
    NSString *pageSize;//一页显示列表数
    NSString *queryTime;//查询时间
    NotFindDeviceView *findView;
}
@property (nonatomic, strong) UIButton *noNetWorkBtn;     //NoNetWorkBtn
@property (nonatomic, strong) IGHomePageApi *homePageApi;
@property (nonatomic, strong) IGHomePageLastUploadApi *homePageLastUploadApi;//最新上线
@property (nonatomic, strong) IGHomeHDApi *homeHDApi;//推荐画单
@property (nonatomic, strong) IGHomeDailyActivityApi *dailyActivityApi;//专题活动
@property (nonatomic, strong) IGHomeArtistApi *artistApi;//艺术家列表


@property (nonatomic, strong) NSMutableArray *bannerArr;        //Banner
@property (nonatomic, strong) NSMutableArray *homeMenuArr;      //八个图片按钮
@property (nonatomic, strong) NSMutableArray *recommendArr;     //推荐模块
@property (nonatomic, strong) NSMutableArray *reusableViewArr;
@property (nonatomic, strong) NSMutableArray *homeHDArr;
@property (nonatomic, strong) NSMutableArray *homeDailyArr;
@property (nonatomic, strong) NSMutableArray *homeActivityArr;
@property (nonatomic, strong) NSMutableArray *homeArtistArr;


@property (nonatomic, strong) NSArray *iGalleryListArr;
@property (nonatomic, strong) IGiGalleryListApi *api;
@property (nonatomic, strong) UICollectionView *collectionV;

@end

@implementation HomeViewController


-(UICollectionView *)collectionV
{
    if (!_collectionV) {
        _collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
        _collectionV.dataSource = self;
        _collectionV.delegate = self;
        _collectionV.emptyDataSetDelegate = self;
        _collectionV.emptyDataSetSource = self;
        _collectionV.backgroundColor = [UIColor c3Color];
        [_collectionV registerClass:[HomeBannerCell class] forCellWithReuseIdentifier:@"HomeBannerCell"];
        [_collectionV registerClass:[HomeViewBtnCell class] forCellWithReuseIdentifier:@"HomeViewBtnCell"];
        [_collectionV registerClass:[HomeReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HomeReusableView"];
        [_collectionV registerClass:[HomeHDCell class] forCellWithReuseIdentifier:@"HomeHDCell"];
        [_collectionV registerNib:[UINib nibWithNibName:@"HomeDailyCell" bundle:nil] forCellWithReuseIdentifier:@"HomeDailyCell"];
        [_collectionV registerNib:[UINib nibWithNibName:@"HomeActivityCell" bundle:nil] forCellWithReuseIdentifier:@"HomeActivityCell"];
        [_collectionV registerClass:[HomeArtistCollectionCell class] forCellWithReuseIdentifier:@"HomeArtistCollectionCell"];
        [_collectionV registerClass:[HomeArtWorkCell class] forCellWithReuseIdentifier:@"HomeArtWorkCell"];
        
        __weak typeof(self) weakSelf = self;
        [_collectionV ig_setHeaderWithRefreshingBlock:^{
            pageNumber = @"0";
            pageSize = @"10";
            [weakSelf dataRequest];
        }];
    }
    return _collectionV;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationItem setTitle:NSLocalizedString(@"iGallery", nil)];
    [self ig_setupLeftBarButtonItemWithTitle:nil image:[UIImage imageNamed:@"home_3"] highLightedImage:[UIImage imageNamed:@"home_3"]];
    [self ig_setupRightButtonItemWithTitle:nil image:[UIImage imageNamed:@"app_search_icon"] highLightedImage:[UIImage imageNamed:@"app_search_icon"]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(networkChanged:)
                                                 name:AFNetworkingReachabilityDidChangeNotification
                                               object:nil];

    [self.view addSubview:self.noNetWorkBtn];
    [self.view addSubview:self.collectionV];
    
    [self.noNetWorkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(NavigationMagin);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0);
    }];
    
    [self.collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.noNetWorkBtn.mas_bottom);
    }];
    [self initBaseData];

    [self dataRequest];
    [IGPopPictureManager popPicture];
    [IGAppVersionManager checkAppVersion];
    self.noNetWorkBtn.hidden = YES;
}

- (void)initBaseData
{
    pageNumber = @"0";
    pageSize = @"10";
    queryTime = @"";
    
    self.homePageApi = [IGHomePageApi new];
    self.homePageLastUploadApi = [IGHomePageLastUploadApi new];
    self.homeHDApi = [IGHomeHDApi new];
    self.dailyActivityApi = [IGHomeDailyActivityApi new];
    self.artistApi = [IGHomeArtistApi new];
    
    self.bannerArr =[@[] mutableCopy];
    self.homeMenuArr = [@[] mutableCopy];
    self.recommendArr = [@[] mutableCopy];
    self.reusableViewArr = [@[] mutableCopy];
    self.homeHDArr = [@[] mutableCopy];
    self.homeDailyArr = [@[] mutableCopy];
    self.homeActivityArr = [@[] mutableCopy];
    self.homeArtistArr = [@[] mutableCopy];
//
    NSArray *strArr = @[NSLocalizedString(@"home1", nil),NSLocalizedString(@"home2", nil), NSLocalizedString(@"home3", nil), NSLocalizedString(@"home4", nil), NSLocalizedString(@"home5", nil)];
    for (int i = 0 ; i < 5 ; i++)
    {
        IGHomeReusableModel *model = [IGHomeReusableModel new];
        model.titleStr = strArr[i];
        CGFloat wid = [Tool widthForLabel:strArr[i] fontSize:18];
        model.titleWid = wid;
        if (i == 0 || i == 1 || i == 3)
        {
            model.type = normalType;
        }
        else
        {
            model.type = withoutMoreBtnType;
        }
        [self.reusableViewArr addObject:model];
    }
}

- (UIButton *)noNetWorkBtn
{
    if (!_noNetWorkBtn) {
        _noNetWorkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _noNetWorkBtn.backgroundColor = [UIColor colorWithHex:@"f5c2c2"];
        [_noNetWorkBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_noNetWorkBtn setTitle:[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"Current network not available.", nil),NSLocalizedString(@"Please check your network setting.", nil)] forState:UIControlStateNormal];
        _noNetWorkBtn.titleLabel.font = [UIFont sAutoLayoutFont:18];
        [_noNetWorkBtn setImage:[UIImage imageNamed:@"noNet_bg"] forState:UIControlStateNormal];
        [_noNetWorkBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10)];
        [_noNetWorkBtn setTapActionWithBlock:^{
            [UIViewController ig_pushViewControllerClass:[IGNoNetWorkVC class] animated:YES];
        }];
    }
    return _noNetWorkBtn;
}

- (void)dataRequest
{
    __weak typeof(self) weakSelf = self;
    [self.homePageApi startWithDecodeClass:[IGHomePageResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [weakSelf.collectionV ig_endHeaderRefreshing];
        if (responseObject) {
            IGHomePageResp *resp = responseObject;
            IGHomePageModel *model = resp.data;
            weakSelf.bannerArr = [NSMutableArray arrayWithArray:model.lstBannerApp];
            weakSelf.homeMenuArr = [NSMutableArray arrayWithArray:model.lstMenuApp];
            [weakSelf.collectionV reloadData];
            }
//        dispatch_async(dispatch_get_main_queue(), ^{
//            [weakSelf.collectionV reloadData];
//        });
    }];
    [self.homeHDApi startWithDecodeClass:[IGHomeHDResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [weakSelf.collectionV ig_endHeaderRefreshing];
        if (responseObject) {
            IGHomeHDResp *resp = responseObject;
            IGHomeHDModel *model = resp.data;
            weakSelf.homeHDArr = [NSMutableArray arrayWithArray:model.drawlist];
            [weakSelf.collectionV reloadData];
        }
    }];
    
    [self.dailyActivityApi startWithDecodeClass:[IGHomeDailyActivityResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [weakSelf.collectionV ig_endHeaderRefreshing];
        if (responseObject) {
            IGHomeDailyActivityResp *resp = responseObject;
            IGHomeDailyActivityModel *model = resp.data;
            weakSelf.homeDailyArr = [NSMutableArray arrayWithArray:model.specialList];
            weakSelf.homeActivityArr = [NSMutableArray arrayWithArray:model.activityList];
            [weakSelf.collectionV reloadData];
        }
    }];
    
    [self.artistApi startWithDecodeClass:[IGHomeArtistResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [weakSelf.collectionV ig_endHeaderRefreshing];
        if (responseObject) {
            IGHomeArtistResp *resp = responseObject;
            IGHomeArtistModel *model = resp.data;
            weakSelf.homeArtistArr = [NSMutableArray arrayWithArray:model.memberList];
            [weakSelf.collectionV reloadData];
        }
    }];
    
    [self dataRequest1];
}

- (void)dataRequest1
{
    __weak typeof(self) weakSelf = self;
    self.homePageLastUploadApi.pageSize = pageSize;
    self.homePageLastUploadApi.pageNumber = pageNumber;
    self.homePageLastUploadApi.queryTime = queryTime;
    [self.homePageLastUploadApi startWithDecodeClass:[IGHomePageLastUploadResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [_collectionV ig_endHeaderRefreshing];
        [_collectionV ig_endFooterRefreshing];
        if (responseObject) {
            IGHomePageLastUploadResp *resp = responseObject;
            IGHomePageLastUploadModel *model = resp.data;
            if (model.lstWork && model.lstWork.count > 0)
            {
                [weakSelf setupFooter];
            }
            else
            {
                [_collectionV ig_endFooterRefreshingWithNoMoreData];
            }
            queryTime = model.time;
            if ([pageNumber isEqualToString:@"0"])
            {
                _recommendArr = [NSMutableArray arrayWithArray:model.lstWork];
            }
            else
            {
                [_recommendArr addObjectsFromArray:model.lstWork];
            }
            [_collectionV reloadData];
        }
    }];
}

- (void)setupFooter
{
    @KWeakObj(self)
    [_collectionV ig_setFooterWithRefreshingBlock:^{
        pageNumber = [NSString stringWithFormat:@"%ld", [pageNumber integerValue] + 1];
        [selfWeak dataRequest1];
    }];
}

- (void)pushToDev:(IGArtWorkModel *)model
{
    [self presentMessageTips:NSLocalizedString(@"Pushing...", nil)];
    IGiGalleryEqu *equ = self.iGalleryListArr[0];
    IGiGalleryPushApi *pushApi = [[IGiGalleryPushApi alloc] initWithMacIds:@[equ.macId] pIds:@[model.aId]];
    [pushApi startWithDecodeClass:[IGiGalleryPushResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            [self presentMessageTips:NSLocalizedString(@"Pushed Successfully...", nil)];
        }
    }];
}

- (void)ig_leftButtonPressed:(id)sender
{
    [UIViewController ig_pushViewControllerClass:[IGMyiGalleryVC class] animated:YES];
}

- (void)ig_rightButtonPressed:(id)sender
{
    [UIViewController ig_pushViewControllerClass:[IGSearchVC class] animated:YES];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 7;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return self.bannerArr.count ? 1 : 0;
    }
    else if (section == 1)
    {
        return self.homeMenuArr.count ? 1 : 0;
    }
    else if (section == 2)
    {
        return self.homeHDArr.count ? : 0;
    }
    else if (section == 3)
    {
        return self.homeDailyArr.count ? : 0;
//        if (self.homeDailyArr.count > 0 && self.homeActivityArr.count > 0)
//        {
//             + ;
//        }
//        return 0;
    }
    else if (section == 4)
    {
        return self.homeActivityArr.count ? : 0;
    }
    else if (section == 5)
    {
        return self.homeArtistArr.count ? 1 : 0;
    }
    else if (section == 6)
    {
        return _recommendArr.count ? : 0;
    }
    return 0;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return CGSizeMake(KSCREENWIDTH, BANNERHEIGHT) ;
    }
    else if (indexPath.section == 1)
    {
        return CGSizeMake(KSCREENWIDTH * 72 / 75, KSCREENWIDTH * 328 / 750);
    }
    else if (indexPath.section == 2)
    {
        return CGSizeMake((KSCREENWIDTH - 30) / 3, (KSCREENWIDTH - 30) / 3 + 38);
    }
    else if (indexPath.section == 3)
    {
        return CGSizeMake(KSCREENWIDTH, 90);
    }
    else if (indexPath.section == 4)
    {
        return CGSizeMake(KSCREENWIDTH, (KSCREENWIDTH - 14) * 410 / 724 + 102);
    }
    else if (indexPath.section == 5)
    {
        return CGSizeMake(KSCREENWIDTH, 243);
    }
    else if (indexPath.section == 6)
    {
        if (self.recommendArr.count > 0)
        {
            IGArtWorkModel *recommend = self.recommendArr[indexPath.row];
            if ([recommend.plates intValue] == 1)
            {
                return CGSizeMake(KSCREENWIDTH, 285);
            }
            else
            {
                return CGSizeMake(KSCREENWIDTH, 440);
            }
        }
    }
    return CGSizeZero;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        HomeBannerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndexPath:indexPath];
        cell.bannerArr = self.bannerArr;
        return cell;
    }
    else if (indexPath.section == 1)
    {
        HomeViewBtnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeViewBtnCell" forIndexPath:indexPath];
        cell.menuArr = self.homeMenuArr;
        return cell;
    }
    else if (indexPath.section == 2)
    {
        IGDrawModel *hd = self.homeHDArr[indexPath.row];
        HomeHDCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHDCell" forIndexPath:indexPath];
        cell.hdModel = hd;
        return cell;
    }
    else if (indexPath.section == 3)
    {
        HomeDailyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeDailyCell" forIndexPath:indexPath];
//        if (indexPath.row < self.homeDailyArr.count)
//        {
            IGHomeDaily *daily = self.homeDailyArr[indexPath.row];
            [cell.imageV sd_setImageWithURL:[NSURL URLWithString:daily.imageSmall] placeholderImage:[UIImage imageFromColor:[UIColor mainRandomColor]]];
            cell.titleL.text = daily.title;
            cell.subTitleL.text = daily.subTitle;
        return cell;
    }
    else if (indexPath.section == 4)
    {
        HomeActivityCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeActivityCell" forIndexPath:indexPath];
        IGHomeActivity *activity = self.homeActivityArr[indexPath.row];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:activity.image] placeholderImage:[UIImage imageFromColor:[UIColor mainRandomColor]]];
        cell.titleL.text = activity.title;
        cell.subTitleL.text = activity.subTitle;
        return cell;
    }
    else if (indexPath.section == 5)
    {
        HomeArtistCollectionCell  *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeArtistCollectionCell" forIndexPath:indexPath];
        if (_homeArtistArr.count)
        {
            cell.dataArr = self.homeArtistArr;
        }
        return cell;
    }
    else if (indexPath.section == 6)
    {
        HomeArtWorkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeArtWorkCell" forIndexPath:indexPath];
        IGArtWorkModel *recommend = self.recommendArr[indexPath.row];
        cell.recommendDetail = recommend;
        __weak typeof(self) weakSelf = self;
        cell.pushBlock = ^{
            //             1、没有绑定设备——引导用户绑定设备
            //             2、绑定一台设备——直接推送
            //             3、绑定多台设备——跳转到选择设备列表
            self.api = [[IGiGalleryListApi alloc] initWithType:IGiGalleryListTypeSuccess];
            [self.api startWithDecodeClass:[IGiGalleryListResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
                if (responseObject)
                {
                    IGiGalleryListResp *resp = responseObject;
                    IGiGalleryListModel *model1 = resp.data;
                    weakSelf.iGalleryListArr = [NSArray arrayWithArray:model1.equs];
                    if (self.iGalleryListArr.count == 0)
                    {
                        findView = [NotFindDeviceView showNotFindDeviceView];
                        findView.bangdingBlock = ^{
                            [UIViewController ig_pushViewControllerClass:[IGMyiGalleryVC class] animated:YES];
                        };
                    } else if (self.iGalleryListArr.count == 1) {
                        [weakSelf pushToDev:recommend];
                    } else {
                        IGPushiGalleryListVC *listVC = [[IGPushiGalleryListVC alloc] initWithType:IGPushiGalleryType1N];
                        listVC.recommend = recommend;
                        [UIViewController ig_pushViewController:listVC animated:YES];
                    }
                }
            }];
        };
        return cell;
    }
    return nil;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader)
    {
        if (indexPath.section >= 2)
        {
        IGHomeReusableModel *model = self.reusableViewArr[indexPath.section - 2];
        HomeReusableView *reusableV = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HomeReusableView" forIndexPath:indexPath];
        reusableV.model = model;
        [reusableV setNeedsLayout];
            if (indexPath.section == 2)
            {
                reusableV.block = ^{
//                    跳转画单界面
                    [UIViewController ig_pushViewController:[[HomeHDVC alloc] init] animated:YES];
                };
            }
            else if (indexPath.section == 3)
            {
                reusableV.block = ^{
                    //跳转原专题界面
                    [UIViewController ig_pushViewController:[[TopicVC alloc] init] animated:YES];
                };
            }
            else if (indexPath.section == 5)
            {
                reusableV.block = ^{
                    //跳转原艺术家界面
                    [UIViewController ig_pushViewController:[[ArtistTableVC alloc] init] animated:YES];
                };
            }
        return reusableV;
        }
    }
    return nil;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    if (section == 2 && self.homeHDArr.count > 0)
    {
        return CGSizeMake(KSCREENWIDTH, 60);
    }
    else if (section == 3 && self.homeDailyArr.count > 0)
    {
        return CGSizeMake(KSCREENWIDTH, 60);
    }
    else if (section == 4 && self.homeActivityArr.count > 0)
    {
        return CGSizeMake(KSCREENWIDTH, 60);
    }
    else if (section == 5 && self.homeArtistArr.count > 0)
    {
        return CGSizeMake(KSCREENWIDTH, 60);
    }
    else if (section == 6 && self.recommendArr.count > 0)
    {
        return CGSizeMake(KSCREENWIDTH, 60);
    }
    return CGSizeZero;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    return CGSizeZero;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionVeliew layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (section == 1)
    {
        return UIEdgeInsetsMake(0, 35, 0, 35);
    }
    if (section == 2)
    {
        return UIEdgeInsetsMake(0, 7.5, 18, 7.5);
    }
    if (section == 3)
    {
        return UIEdgeInsetsMake(0, 0, 18, 0);
    }
    return UIEdgeInsetsZero;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    if (section == 2)
    {
        return 18;
    }
    if (section == 3)
    {
        return 18;
    }
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    if (section == 2)
    {
        return 7.5;
    }
    return 0;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2 && self.homeHDArr.count > 0)
    {
        //画单详情页
        IGDrawModel *hd = self.homeHDArr[indexPath.row];
        IGPictureListDetailVC *vc = [[IGPictureListDetailVC alloc] init];
        vc.drawlistId = hd.drawId;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
    if (indexPath.section == 3 && self.homeDailyArr.count > 0)
    {
        IGHomeDaily *daily = self.homeDailyArr[indexPath.row];
        ZTXQViewController *vc = [[ZTXQViewController alloc] init];
        vc.s_id = daily.sid;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
    if (indexPath.section == 4 && self.homeActivityArr.count > 0)
    {
        //活动推荐
        IGHomeActivity *activity = self.homeActivityArr[indexPath.row];
        if ([activity.type isEqualToString:@"1"]) {
            IGExhibitionVC * vc = [IGExhibitionVC new];
            vc.activityId = activity.aid;
            [UIViewController ig_pushViewController:vc animated:YES];
        } else if ([activity.type isEqualToString:@"2"]) {
            IGCompetitionVC * vc = [IGCompetitionVC new];
            vc.activityId = activity.aid;
            [UIViewController ig_pushViewController:vc animated:YES];
        }
    }
    else if (indexPath.section == 6 && self.recommendArr.count > 0)
    {
        IGArtWorkModel *recommend = self.recommendArr[indexPath.row];
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = recommend.aId;
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
}

#pragma mark -Empty

- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    IGEmptyView *emptyView = [[IGEmptyView alloc] init];
    emptyView.title = NSLocalizedString(@"No Data", nil);
    emptyView.requestApi = _homePageApi;
    return emptyView;
}

- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
}

- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView {
    [self dataRequest];
}

#pragma mark -netWork
- (void)networkChanged:(NSNotification *)notification
{
    if ([IGNetReachable isReachable]) {
        [self.noNetWorkBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        self.noNetWorkBtn.hidden = YES;
    } else {
        [self.noNetWorkBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(50);
        }];
        self.noNetWorkBtn.hidden = NO;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
